package com.redislock.aop.tool.controller.index;

import cn.hutool.core.util.RandomUtil;
import com.redislock.aop.tool.domain.AjaxResult;
import com.redislock.aop.tool.util.RedisUtil;
import com.redislock.aop.tool.util.ToolUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/index")
public class IndexController {
    @GetMapping("token")
    public AjaxResult token() {
        //可以把项目里的访问用户名放到里面
        String user = "wangming";
        String token = RandomUtil.randomString(23);
        RedisUtil.setnx(ToolUtils.getTokenKey(user,token),"1",30L, TimeUnit.MINUTES);
        return AjaxResult.success(token);
    }
}
